var t, e = require("../../@babel/runtime/helpers/interopRequireDefault"), a = e(require("../../@babel/runtime/regenerator")), i = e(require("../../@babel/runtime/helpers/asyncToGenerator")), n = require("../../1D8980678A52ABCF7BEFE860FD67FE64.js"), r = require("../../E52ED4948A52ABCF8348BC934D77FE64.js"), s = require("../../3F2EFC058A52ABCF59489402DCA7FE64.js"), o = getApp();

Page({
    data: {
        douyin: n.IMGPATH + "but_douyin.png",
        icons: {
            icon01: n.IMGPATH + "ic_luck.png",
            icon02: n.IMGPATH + "qinggan.png",
            icon03: n.IMGPATH + "quwei2.png",
            icon04: n.IMGPATH + "xingge.png",
            icon05: n.IMGPATH + "ic_hot.png",
            back: n.IMGPATH + "back_left_01.png",
            back2: n.IMGPATH + "back_left_02.png"
        },
        keyWord: "",
        pageNumber: 1,
        pageSize: 10,
        questionCategory: "",
        list: [],
        status: !1,
        topDistance: 0,
        backHeight: 0,
        backWidth: 0,
        leftDistance: 0,
        lineHeight: "",
        activeTopStatus: !1,
        paddingHeight: 0
    },
    onLoad: function(t) {
        var e = this, a = t.cate, i = o.globalData.headerBtnPosi, n = o.globalData.winWidth, r = 2 * o.globalData.statusBarHeight, s = n - i.right, c = i.height, u = 2 * c, g = 2 * c + 36;
        wx.showLoading({
            title: "加载中"
        });
        var l = decodeURIComponent(a);
        this.setData({
            topDistance: r,
            lineHeight: g,
            paddingHeight: g + 2 * r,
            leftDistance: s,
            backWidth: u,
            backHeight: c,
            questionCategory: l
        }, function() {
            wx.setNavigationBarTitle({
                title: l
            }), e.fetchData();
        });
    },
    fetchData: (t = (0, i.default)(a.default.mark(function t() {
        var e, i, n, o, c, u, g, l, d, p;
        return a.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                return e = this.data, i = e.keyWord, n = e.pageNumber, o = e.pageSize, c = e.questionCategory, 
                u = e.list, g = e.status, t.next = 3, (0, r.ajax)({
                    url: "/api/testQuestion/getPager",
                    data: {
                        keyWord: i,
                        pageSize: o,
                        pageNumber: n,
                        questionCategory: c
                    }
                });

              case 3:
                if (l = t.sent, wx.hideLoading(), l.code) {
                    t.next = 15;
                    break;
                }
                if ((d = l.data.data).length) {
                    t.next = 9;
                    break;
                }
                return t.abrupt("return");

              case 9:
                for (d.length >= o ? (n++, g = !0) : g = !1, p = 0; p < d.length; p++) d[p].reads = (0, 
                s.getRandomNumberByRange)(1e3, 1e5);
                u = u.concat(d), this.setData({
                    pageNumber: n,
                    list: u,
                    status: g
                }), t.next = 16;
                break;

              case 15:
                this.setData({
                    status: !1
                });

              case 16:
                return t.abrupt("return", g);

              case 17:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function() {
        return t.apply(this, arguments);
    }),
    bindscroll: function(t) {
        var e = this.data, a = e.topDistance, i = e.activeTopStatus, n = t.detail.scrollTop;
        n > 2 * a && !i && this.setData({
            activeTopStatus: !0
        }), n <= 2 * a && i && this.setData({
            activeTopStatus: !1
        });
    },
    lowerScroll: function() {
        this.data.status && this.fetchData();
    },
    jumpDetail: function(t) {
        var e = t.currentTarget.dataset.id;
        if (!e) throw new Error("detail id 缺失");
        wx.navigateTo({
            url: "/pages/detail/index?id=" + e
        });
    },
    backHandle: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    onShareAppMessage: function(t) {
        var e = this.data.questionCategory, a = "/pages/list/index?cate=" + encodeURIComponent(e), i = "";
        return "趣味测试" == e ? i = icons.icon03 : "爱情测试" == e ? i = icons.icon02 : "缘分测试" == e ? i = icons.icon01 : "性格测试" == e && (i = icons.icon04), 
        {
            title: e,
            imageUrl: i,
            path: a
        };
    }
});